package com.ruoyi.web.controller.tk;

import java.util.List;

import com.ruoyi.common.utils.Cascader;
import com.ruoyi.paper.domain.QtPaperTkNums;
import com.ruoyi.system.domain.QtOption;
import com.ruoyi.system.mapper.QtOptionMapper;
import com.ruoyi.system.service.IQtOptionService;
import com.ruoyi.system.service.impl.pc;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QtTk;
import com.ruoyi.system.service.IQtTkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题库管理Controller
 * 
 * @author zqq
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/tk/tk")
public class QtTkController extends BaseController
{
    @Autowired
    private IQtTkService qtTkService;
    @Autowired
    IQtOptionService iQtOptionService;
    @Autowired
    com.ruoyi.system.service.impl.pc pc;

    /**
     * 查询题库管理列表
     */
    @PreAuthorize("@ss.hasPermi('tk:tk:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtTk qtTk) throws Exception {
        //pc.pc1();
        startPage();
        List<QtTk> list = qtTkService.selectQtTkList(qtTk);
        return getDataTable(list);
    }
    /**
     * 查询题库管理列表
     */
    @PreAuthorize("@ss.hasPermi('tk:tk:optionList')")
    @GetMapping("/optionList")
    public List<QtOption> optionList(QtOption qtOption) throws Exception {
        return iQtOptionService.getOptions(qtOption);
    }
    /**
     * 导出题库管理列表
     */
    @PreAuthorize("@ss.hasPermi('tk:tk:export')")
    @Log(title = "题库管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtTk qtTk)
    {
        List<QtTk> list = qtTkService.selectQtTkList(qtTk);
        ExcelUtil<QtTk> util = new ExcelUtil<QtTk>(QtTk.class);
        return util.exportExcel(list, "题库管理数据");
    }

    /**
     * 获取题库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tk:tk:query')")
    @GetMapping(value = "/{tkId}")
    public AjaxResult getInfo(@PathVariable("tkId") String tkId)
    {
        return AjaxResult.success(qtTkService.selectQtTkByTkId(tkId));
    }

    /**
     * 新增题库管理
     */
    @PreAuthorize("@ss.hasPermi('tk:tk:add')")
    @Log(title = "题库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtTk qtTk)
    {
        return toAjax(qtTkService.insertQtTk(qtTk));
    }

    /**
     * 修改题库管理
     */
    @PreAuthorize("@ss.hasPermi('tk:tk:edit')")
    @Log(title = "题库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtTk qtTk)
    {
        return toAjax(qtTkService.updateQtTk(qtTk));
    }

    /**
     * 删除题库管理
     */
    @PreAuthorize("@ss.hasPermi('tk:tk:remove')")
    @Log(title = "题库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tkIds}")
    public AjaxResult remove(@PathVariable String[] tkIds)
    {
        return toAjax(qtTkService.deleteQtTkByTkIds(tkIds));
    }
    /**
     * 获取级联数据
     */
    @PreAuthorize("@ss.hasPermi('qt:user:csacade')")
    @GetMapping("/cascade")
    public List<Cascader> cascade()
    {
        return qtTkService.getCascader();
    }
    /**
     * 获取二级级联数据
     */
    @PreAuthorize("@ss.hasPermi('qt:user:csacade2')")
    @GetMapping("/cascade2")
    public List<Cascader> cascade2()
    {
        return qtTkService.getCascader2();
    }
    /**
     * 获取题库数量
     */
    @PreAuthorize("@ss.hasPermi('qt:user:tkNums')")
    @GetMapping("/tkNums")
    public List<QtPaperTkNums> tkNums(QtTk qtTk)
    {
        return qtTkService.getnums(qtTk);
    }
    /**
     * 获取课程试卷数据
     */
    @PreAuthorize("@ss.hasPermi('qt:user:getCascaderByPaper')")
    @GetMapping("/getCascaderByPaper")
    public List<Cascader> getCascaderByPaper()
    {
        return qtTkService.getCascaderByPaper();
    }

}
